package gui;

import SqlConnect.SqlConnection;

import javax.swing.*;
import java.awt.*;
import java.sql.SQLException;

public class MainFrame {
    public static SqlConnection sql;
    private static JPanel p;
    private static JFrame f;

    public MainFrame(String user, String password) {
        try {
            sql = new SqlConnection(user, password);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        f = new JFrame("投资管理系统");
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setResizable(false);
        p = new LoginPage();
        f.add(p);
        f.setVisible(true);
        setCenter(480, 270);
    }

    public static void update(JPanel p) {
        f.remove(MainFrame.p);
        MainFrame.p = p;
        f.add(MainFrame.p);
        f.setVisible(true);
    }

    public static void setCenter(int width, int height) {
        f.setSize(width, height);
        int windowWidth = f.getWidth();
        int windowHeight = f.getHeight();
        Toolkit kit = Toolkit.getDefaultToolkit();
        Dimension screenSize = kit.getScreenSize();
        int screenWidth = screenSize.width;
        int screenHeight = screenSize.height;
        f.setLocation(screenWidth / 2 - windowWidth / 2, screenHeight / 2 - windowHeight / 2);
    }
}